import QtQuick 1.1
import QtCommercial.Chart 1.2

Rectangle {
    width: 447
    height: 250
    color: "#00000000"
    border.color: "#00000000"
    Column {
        id: column1
        anchors.fill: parent
        width: parent.width
        height: parent.height

        ChartView {
            id: chart
            width: parent.width
            height: parent.height
            ValueAxis {
                        id: xAxis
                        tickCount: 25
                        labelFormat: "%d"
                        max: 24
                    }
            ValueAxis {
                        id: yAxis
                        labelFormat: "%d\%"
                    }

            title: "CPU/内存曲线"
            theme: ChartView.ChartThemeLight

            SplineSeries {
                axisX: xAxis
                axisY: yAxis
                visible: false
            }

            SplineSeries {
                name: "CPU"
                id: cpu_line
            }
            SplineSeries {
                name: "内存"
                id: mem_line
            }

        }
    }
    function addXYPoint(name,x,y) {
       if(name === "cpu_line")
       {
           for(var i=0; i<x.length; i++)
           {
               cpu_line.append(x[i], y[i]);
               if(y[i]>yAxis.max) {
                   yAxis.max = y[i];
               }
           }
       }

       else if(name === "mem_line")
       {
           for(var i=0; i<x.length; i++)
           {
               mem_line.append(x[i], y[i]);
               if(y[i]>yAxis.max) {
                   yAxis.max = y[i];
               }
           }
       }
       if(yAxis.max <= 4) {
           yAxis.max = 4;
       }
       else {
           yAxis.max += yAxis.max/4;
       }
    }

}
